#!/usr/bin/env bash

# this file is part of the "flashheart" software program
# 
# it is hereby placed in the PUBLIC DOMAIN by its author
# 
# there is NO WARRANTY, whether express or implied
# 
# by using this software, you agree to assume any and all risks of
# such use, and that, to the maximum extent permitted by law, neither
# the author of this software (the "author"), nor the party that
# supplied this software to you (the "supplier"), is responsible for
# any damage or loss caused to you or to any third party, even if
# said damage or loss is directly attributable to your use of this
# software, and even if the possibility of said damage or loss was
# known to or reasonably forseeable by the author or the supplier or
# both

set -o errexit

gcc -static -O2 -o flashheart -x c --std=c99 ./flashheart.c -lmpsse -lftdi -lusb

echo -n \
'compilation successful.
the usage of the program will now being printed to the terminal.
this is for informational purposes.

usage:
  ./flashheart PAGESIZE CHIPSIZE SPISPEED (read|flash)

usually, PAGESIZE=256 works
use CHIPSIZE=$((2**22)) for 4MiB chips, **23 for 8MiB chips, etc
use SPISPEED=20000000 or so, less if you have longish wires
read mode produces out.bin
flash mode consumes inp.bin

additional, less useful, modes:
status
  - reads status information (0x05 command, 1-byte result)
chiperase
  - discrete erase of the chip
  - not necessary to run this before using flash mode
mxrdid
  - reads additional information (0x9F command, 3-byte result)
'
